/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI.Dialogs;

import GUI.Components.BButton;
import GUI.Components.BTextField;
import GUI.Components.CancelButton;
import General.CurrentData;
import com.jme3.scene.debug.Grid;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.concurrent.Callable;
import javax.swing.JLabel;
import se.datadosen.component.RiverLayout;

/**
 *
 * @author David
 */
public class GridOptionsDialog extends BasicDialog
{

    private BTextField xLinesField = new BTextField("Integer", (String) CurrentData.getConfiguration().getSettings().get("gridx"));
    private BTextField yLinesField = new BTextField("Integer", (String) CurrentData.getConfiguration().getSettings().get("gridy"));
    private BTextField gridGabField = new BTextField("Float", (String) CurrentData.getConfiguration().getSettings().get("gridgap"));
    private BButton okButton = new BButton("Ok");
    private CancelButton cancelButton;

    /**
     *
     */
    public GridOptionsDialog()
    {
        setLayout(new RiverLayout(10, 6));
        cancelButton = new CancelButton(this);
        add("left", new JLabel("Gap:"));
        add("tab hfill", gridGabField);
        add("br left", new JLabel("Lines on x:"));
        add("tab hfill", xLinesField);
        add("br left", new JLabel("Lines on y:"));
        add("tab hfill", yLinesField);
        add("br", okButton);
        add(cancelButton);
        okButton.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                CurrentData.getConfiguration().getSettings().put("gridx", xLinesField.getText());
                CurrentData.getConfiguration().getSettings().put("gridy", xLinesField.getText());
                CurrentData.getConfiguration().getSettings().put("gridgap", gridGabField.getText());
                CurrentData.getConfiguration().save();
                CurrentData.getEditorWindow().getB3DApplication().enqueue(new Callable<Void>()
                {
                    public Void call() throws Exception
                    {
                        CurrentData.getEditorWindow().getB3DApplication().getGridGeometry().setMesh(new Grid(
                                Integer.parseInt(xLinesField.getText()),
                                Integer.parseInt(yLinesField.getText()),
                                Float.parseFloat(gridGabField.getText())));
                        CurrentData.getEditorWindow().getB3DApplication().correctGridLocation();
                        return null;
                    }
                });
                dispose();
            }
        });
        setTitle("Grid Options");
        setResizable(false);
        setModal(false);
        setAlwaysOnTop(true);
        pack();
        setLocationRelativeTo(null);
        setVisible(true);
    }
}